package com.ruoyi.syf.handler.escalation.strategy;

import com.ruoyi.syf.common.constant.EscalationDataType;
import com.ruoyi.syf.handler.escalation.EscalationStrategy;
import com.ruoyi.syf.service.EscalationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * 实时数据上报
 */
@Service
public class RealTimeDataEscalationStrategy implements EscalationStrategy {

    @Resource
    private EscalationService escalationService;

//    @Resource
//    private RealTimeDataMapper realTimeDataMapper;

    @Override
    public boolean escalation() throws ParseException {
        return true;
//        LambdaQueryWrapper<RealTimeData> lqw = new LambdaQueryWrapper<>();
        //查询当天数据
//        lqw.gt(RealTimeData::getCreateTime,DateUtils.getPresentTime());
//        List<RealTimeData> timeData = realTimeDataMapper.selectList(lqw);
//        List<Map<String, Object>> maps = new ArrayList<>();
//        //按企业编码分组
//        Map<String, List<RealTimeData>> entIdCollect = timeData.stream()
//                .collect(Collectors.groupingBy(RealTimeData::getEntId));
//        for (String entId : entIdCollect.keySet()){
//            List<RealTimeData> entIdTimeData = entIdCollect.get(entId);
//            //按最后写入时间分组
//            Map<Date, List<RealTimeData>> timeCollect = entIdTimeData.stream()
//                    .collect(Collectors.groupingBy(RealTimeData::getTime));
//            for (Date time : timeCollect.keySet()){
//                List<RealTimeData> timeData1 = timeCollect.get(time);
//                Map<String, Object> map = new HashMap<>();
//                String uuid = UUID.randomUUID().toString();
//                map.put("dataId",uuid);
//                map.put("enterpriseId",entId);
//                map.put("gatewayId", TCPSocketUtil.GATEWAY_ID);
//                map.put("collectTime", DateUtils.dateTOString(time,DateUtils.YYMMDDHHmmss));
//                map.put("isConnectDataSource",true);//数据联通性
//                map.put("reportType","report");//报文类型：report实时报文，continues断点续传报文
//
//                List<Map<String, Object>> datas = new ArrayList<>();
//                timeData1.forEach(item -> {
//                    Map<String, Object> data = new HashMap<>();
//                    data.put("quotaId",item.getQuotaId());
//                    data.put("value",item.getValue());
//                    datas.add(data);
//                });
//                map.put("datas",datas);
//                maps.add(map);
//            }
//        }
//        return escalationService.socketYQEscalation(maps,getEscalationType());
    }

    @Override
    public String getEscalationType() {
        return EscalationDataType.REAL_TIME.getCode();
    }

}
